﻿//now
//http://ameblo.jp/zzdino/entry-10879482947.html
/*
*nowscript2
*CROSS DOMAIN AJAX
*author James Padolsey (http://james.padolsey.com)
*/

jQuery.ajax = (function(_ajax){
var protocol = location.protocol,
hostname = location.hostname,
exRegex = RegExp(protocol + '//' + hostname),
YQL = 'http' + (/^https/.test(protocol)?'s':'') + '://query.yahooapis.com/v1/public/yql?callback=?',
query = 'select * from html where url="{URL}" and xpath="*"';
function isExternal(url) {
return !exRegex.test(url) && /:\/\//.test(url);}
return function(o) {
var url = o.url;
if ( /get/i.test(o.type) && !/json/i.test(o.dataType) && isExternal(url) ) {
// Manipulate options so that JSONP-x request is made to YQL
o.url = YQL;
o.dataType = 'json';
o.data = {
q: query.replace(
'{URL}',
url + (o.data ?
(/\?/.test(url) ? '&' : '?') + jQuery.param(o.data)
: '')
),
format: 'xml'
};
// Since it's a JSONP request
// complete === success
if (!o.success && o.complete) {
o.success = o.complete;
delete o.complete;
}
o.success = (function(_success){
return function(data) {
if (_success) {
// Fake XHR callback.
_success.call(this, {
responseText: data.results[0]
// YQL screws with <script>s
// Get rid of them
.replace(/<script[^>]+?\/>|<script(.|\s)*?\/script>/gi, '')
}, 'success');
}
};
})(o.success);
}
return _ajax.apply(this, arguments);
};
})(jQuery.ajax);

jQuery(function(){
jQuery.ajaxSetup({
cache:false
});

var nowurl='http://now.ameba.jp/'+jQuery("#userNaviArea a#userNickName").attr("href").split("/")[3]+'/';

var into='<div id="nowbox"><div id="nowhead"><p id="nowname"><a href="'+nowurl+'">'+jQuery("#userNaviArea #userNickName").text()+'<span id="japa">のなう</span><span id="eng">\'s now</span></a></p></div><div id="nowbody"><ul id="nowboxlist"></ul></div><div id="nowtail">presented by <a href="http://ameblo.jp/zzdino/entry-10879482947.html" target="_blank">blogzz</a></div></div>';

if(jQuery('#nowfloor').length){
jQuery('#nowfloor:eq(0)').prepend(into);
}else{
jQuery('.entry:eq(0) .contents').append(into);
}

jQuery('#nowboxlist').load('http://now.ameba.jp/'+jQuery("#userNickName").attr('href').split("/")[3]+'/ #nowListArea li:lt(8)',function(){

jQuery('span.entry','#nowboxlist').removeClass("entry").addClass("nowentry").prev().children().each(function(){
jQuery(this).wrap('<span />').parent('span').text(jQuery(this).text().slice(1,-1));
});

jQuery('div.actions a.action,a.history','#nowboxlist').each(function(){
jQuery(this).attr('href','http://now.ameba.jp'+jQuery(this).attr('href'));
});
});
});